//
//  BaseLoginController.m
//  HB
//
//  Created by 孙智慧 on 16/1/27.
//  Copyright © 2016年 孙智慧. All rights reserved.
//

#import "BaseLoginController.h"
#import "AppDelegate.h"

static NSString *code;
static NSString *mobile;
static NSString *uName;
static NSString *pwd;
static NSInteger sex;

@implementation BaseLoginController

-(void) opSuccessForGet:(id)data andFlag:(NSInteger)flag
{}

-(void) opSuccessForDownLoad:(id)data andFlag:(NSString *)flag
{}

-(void) opFail:(NSString *)errorMessage
{}

-(void) opSuccessForPost:(id)data
{}

#pragma 设置静态变量
+(void)setCode:(NSString *)newCode
{
    code= newCode;
}
+(NSString *) getCode
{
    return  code;
}
+(void)setMobile:(NSString *)newMobile
{
    mobile= newMobile;
}
+(NSString *) getMobile
{
    return mobile;
}
+(void)setUName:(NSString *)newUName
{
   uName = newUName;
}
+(NSString *) getUName
{
    return uName;
}
+(void)setPwd:(NSString *)newPwd
{
    pwd = newPwd;
}
+(NSString *) getPwd
{
    return pwd;
}
+(void)setSex:(NSInteger)newSex
{
    sex = newSex;
}
+(NSInteger ) getSex
{
    return sex;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //地理位置
    
    if (IS_IOS8)
    {
        [UIApplication sharedApplication].idleTimerDisabled = TRUE;
        
        locationmanager = [[CLLocationManager alloc] init];
        
        [locationmanager requestAlwaysAuthorization];        //NSLocationAlwaysUsageDescription
        
        [locationmanager requestWhenInUseAuthorization];     //NSLocationWhenInUseDescription
        
        locationmanager.delegate = self;
    }
    
    [self getCity];

}

-(void)getCity
{
    //__block __weak BaseController *wself = self;
    if (IS_IOS8)
    {
        [[CCLocationManager shareLocation]getCity:^(NSString *cityString) {
            NSLog(@"城市：%@",cityString);
        }];
    }
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    //隐藏导航栏
    [super.navigationController setNavigationBarHidden:YES animated:TRUE];
    
    [super.navigationController setToolbarHidden:YES animated:TRUE];
    
    [self setNavigationBlackGround];
    
    [self setNavigationTitleImage:@"hunba"];
    
    [self setBackButton];

}

-(void) setBackButton
{
    
    UIImage* image = [UIImage imageNamed:@"back"];
    
    UIBarButtonItem *item=[[UIBarButtonItem alloc] init];
    
    [item setBackButtonBackgroundImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  
    [item setBackButtonTitlePositionAdjustment:UIOffsetMake(0.0, -400.0) forBarMetrics:UIBarMetricsDefault];
   
    self.navigationItem.backBarButtonItem = item;

}

-(void) setBaclButtonBySystenItem
{
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:nil];
    self.navigationItem.backBarButtonItem = item;
}

//设置背景
-(void) setNavigationBlackGround
{
    //设置背景
    UIImage *image = [UIImage imageNamed:@"NavigationBar44.png"];
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    NSDictionary *attribute = @{
                                NSForegroundColorAttributeName:[UIColor whiteColor],
                                NSFontAttributeName:[UIFont systemFontOfSize:18]
                                };
    [self.navigationController.navigationBar setTitleTextAttributes:attribute];
}

//设置导航栏中心图
- (void)setNavigationTitleImage:(NSString *)imageName
{
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.contentMode= UIViewContentModeScaleAspectFit;
    self.navigationItem.titleView = imageView;
}

//设置自定义按钮
- (UIButton *)customButton:(NSString *)imageName
                  selector:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 22, 22);
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
}

//设置右侧按钮
- (void)setNavigationRight:(NSString *)title sel:(SEL)sel
{
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:sel];
    self.navigationItem.rightBarButtonItem = item;
}

//显示主页
- (void)hideLanch:(BOOL) isLogin
{
    [[AppDelegate appDeg] showHomePage:isLogin];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
 
}

-(void) waitingFor:(NSString *)labelText andMethod:(SEL)method onTarget:(id)target
{
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    
    [self.view addSubview:HUD];
    
    HUD.delegate = target;
    
    HUD.labelText = labelText;
    
    [HUD showWhileExecuting:method onTarget:target withObject:nil animated:YES];
}

@end
